package Service.Impl;

import Dao.CourseContentMapper;
import Dao.PromotionSpaceMapper;
import Service.PromotionSpaceService;
import domain.PromotionSpace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class PromotionSpaceServiceImpl implements PromotionSpaceService {

    @Autowired
    private PromotionSpaceMapper promotionSpaceMapper;

    @Override
    public List<PromotionSpace> findAllPromotionSpace() {
        List<PromotionSpace> promotionSpaces = promotionSpaceMapper.findAllPromotionSpace();
        return promotionSpaces;
    }

    @Override
    public String toString() {
        return "PromotionSpaceServiceImpl{}";
    }

    @Override
    public void savePromotion(PromotionSpace promotionSpace) {

        //1. 封装数据
        promotionSpace.setSpaceKey(UUID.randomUUID().toString());
        Date date = new Date();
        promotionSpace.setCreateTime(date);
        promotionSpace.setUpdateTime(date);
        promotionSpace.setIsDel(0);

        //2. 调用Mapper方法
        promotionSpaceMapper.savePromotionSpace(promotionSpace);
    }


    /*
             根据Id 查询广告位信息
     */
    @Override
    public PromotionSpace findPromitionById(int id) {

        PromotionSpace promotion = promotionSpaceMapper.findPromotionById(id);
        return promotion;
    }

    @Override
    public void updatePromotion(PromotionSpace promotionSpace) {

        //1. 封住数据
        Date date = new Date();
        promotionSpace.setUpdateTime(date);

        //2. 调用Mapper 方法
        promotionSpaceMapper.updatePromotionSpace(promotionSpace);


    }
}
